﻿-- ============================================================
-- Status Reference Data Synchronization Script
-- ============================================================

CREATE TABLE #Status
(
	[Id] [int] NOT NULL,
	[Name] [nchar](10) COLLATE Latin1_General_CI_AS_KS_WS  NOT NULL
);

SET NOCOUNT ON;


INSERT #Status ([Id],[Name]) VALUES (1, N'OK')
INSERT #Status ([Id],[Name]) VALUES (2, N'WARNING')
INSERT #Status ([Id],[Name]) VALUES (3, N'OFFLINE')


MERGE [dbo].[Status] AS Target
	USING #Status AS Source ON (Target.[Id] = Source.[Id])
		WHEN MATCHED THEN
			UPDATE SET Target.[Name] = Source.[Name]
		WHEN NOT MATCHED BY TARGET THEN
			INSERT ([Id], [Name])
			VALUES ( Source.[Id], Source.[Name])
		WHEN NOT MATCHED BY SOURCE
			THEN DELETE ;

DROP TABLE #Status;

GO
